{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "43df71412f2d446cb5ba19692f136d42",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Plot(antialias=3, axes=['x', 'y', 'z'], background_color=16777215, camera=[4.5, 4.5, 4.5, 0.0, 0.0, 0.0, 1.0, …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\"\"\"\n",
    "Generate the isosurfaces corresponding to a set of thresholds.\n",
    "(These surfaces are not separate meshes).\n",
    "\"\"\"\n",
    "from vtk import vtkQuadric, vtkSampleFunction\n",
    "\n",
    "# Quadric definition. This is a type of implicit function.\n",
    "quadric = vtkQuadric()\n",
    "quadric.SetCoefficients(0.5, 1, 0.2, 0, 0.1, 0, 0, 0.2, 0, 0)\n",
    "\n",
    "# the vtkSampleFunction evaluates quadric over a volume\n",
    "sample = vtkSampleFunction()\n",
    "sample.SetSampleDimensions(40, 40, 40)\n",
    "sample.SetImplicitFunction(quadric)\n",
    "sample.Update()\n",
    "\n",
    "img = sample.GetOutput()  # vtkImageData\n",
    "\n",
    "########################\n",
    "from vtkplotter import *\n",
    "\n",
    "# generate an isosurface the volume for each thresholds\n",
    "ts = [0.1, 0.25, 0.4, 0.6, 0.75, 0.9]\n",
    "\n",
    "# Use c=None to use the default vtk color map. isos is of type Actor\n",
    "isos = Volume(img).isosurface(threshold=ts)\n",
    "\n",
    "show(isos)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
